//#include "Worksheet.h"
#include "Node.h"
#include "Root.h"
#pragma once


using namespace System::Runtime::InteropServices;


using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace RedDot {

	/// <summary>
	/// Summary for AddNodeDialog
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class AddNodeDialog : public System::Windows::Forms::Form
	{
	public:
//		Worksheet *currentWorksheet;
/*		int type,pozycja;
		AddNodeDialog(int Type,int Pozycja)
		{
			InitializeComponent();
			type =Type;
			pozycja = Pozycja;
			//
			//TODO: Add the constructor code here
			//
		}
*/
		
		Root *tree;
		Node *ws;

	public: 
	private: System::Windows::Forms::Button^  button11;
	private: System::Windows::Forms::Button^  button12;
	private: System::Windows::Forms::Button^  button13;
	private: System::Windows::Forms::Button^  button14;
	private: System::Windows::Forms::Button^  button15;
	private: System::Windows::Forms::Button^  button16;
	private: System::Windows::Forms::Button^  button17;
	private: System::Windows::Forms::PictureBox^  pictureBox1;
	private: System::Windows::Forms::Button^  button4;


			 int type;
	private: System::Windows::Forms::CheckBox^  checkBox1;
	private: System::Windows::Forms::CheckBox^  checkBox2;
			 int link;
			 
	public:	AddNodeDialog(int Type,Root* tr,Node *tmp)
		{
			InitializeComponent();
			tree=tr;
			ws=tmp;
			type=Type;
			checkBox1->Checked=ws->link;
			
		}
	public:	AddNodeDialog(int Type,Root* tr,Node *tmp,std::string name)
		{
			InitializeComponent();
			tree=tr;
			ws=tmp;
			type=Type;
			checkBox1->Checked=ws->link;
			String^ text=gcnew System::String(ws->getNodeName().c_str());
			this->richTextBox1->Text = text;
			
		}
	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~AddNodeDialog()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::RichTextBox^  richTextBox1;
	protected: 
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;

	protected: 
















	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->button11 = (gcnew System::Windows::Forms::Button());
			this->button12 = (gcnew System::Windows::Forms::Button());
			this->button13 = (gcnew System::Windows::Forms::Button());
			this->button14 = (gcnew System::Windows::Forms::Button());
			this->button15 = (gcnew System::Windows::Forms::Button());
			this->button16 = (gcnew System::Windows::Forms::Button());
			this->button17 = (gcnew System::Windows::Forms::Button());
			this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
			this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
			this->SuspendLayout();
			// 
			// richTextBox1
			// 
			this->richTextBox1->Location = System::Drawing::Point(12, 12);
			this->richTextBox1->Multiline = false;
			this->richTextBox1->Name = L"richTextBox1";
			this->richTextBox1->Size = System::Drawing::Size(272, 164);
			this->richTextBox1->TabIndex = 0;
			this->richTextBox1->Text = L"";
			this->richTextBox1->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &AddNodeDialog::richTextBox1_KeyDown);
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(302, 12);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(77, 37);
			this->button1->TabIndex = 1;
			this->button1->Text = L"Dodaj";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &AddNodeDialog::button1_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(302, 67);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(77, 37);
			this->button2->TabIndex = 2;
			this->button2->Text = L"Anuluj";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &AddNodeDialog::button2_Click);
			// 
			// button11
			// 
			this->button11->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(192)), static_cast<System::Int32>(static_cast<System::Byte>(255)), 
				static_cast<System::Int32>(static_cast<System::Byte>(192)));
			this->button11->Location = System::Drawing::Point(195, 256);
			this->button11->Name = L"button11";
			this->button11->Size = System::Drawing::Size(23, 23);
			this->button11->TabIndex = 17;
			this->button11->UseVisualStyleBackColor = false;
			this->button11->Visible = false;
			// 
			// button12
			// 
			this->button12->BackColor = System::Drawing::Color::Fuchsia;
			this->button12->Location = System::Drawing::Point(166, 256);
			this->button12->Name = L"button12";
			this->button12->Size = System::Drawing::Size(23, 23);
			this->button12->TabIndex = 16;
			this->button12->UseVisualStyleBackColor = false;
			this->button12->Visible = false;
			// 
			// button13
			// 
			this->button13->BackColor = System::Drawing::Color::Silver;
			this->button13->Location = System::Drawing::Point(137, 256);
			this->button13->Name = L"button13";
			this->button13->Size = System::Drawing::Size(23, 23);
			this->button13->TabIndex = 15;
			this->button13->UseVisualStyleBackColor = false;
			this->button13->Visible = false;
			// 
			// button14
			// 
			this->button14->BackColor = System::Drawing::Color::Yellow;
			this->button14->Location = System::Drawing::Point(108, 256);
			this->button14->Name = L"button14";
			this->button14->Size = System::Drawing::Size(23, 23);
			this->button14->TabIndex = 14;
			this->button14->UseVisualStyleBackColor = false;
			this->button14->Visible = false;
			// 
			// button15
			// 
			this->button15->BackColor = System::Drawing::Color::SeaGreen;
			this->button15->Location = System::Drawing::Point(79, 256);
			this->button15->Name = L"button15";
			this->button15->Size = System::Drawing::Size(23, 23);
			this->button15->TabIndex = 13;
			this->button15->UseVisualStyleBackColor = false;
			this->button15->Visible = false;
			// 
			// button16
			// 
			this->button16->BackColor = System::Drawing::Color::RoyalBlue;
			this->button16->Location = System::Drawing::Point(50, 256);
			this->button16->Name = L"button16";
			this->button16->Size = System::Drawing::Size(23, 23);
			this->button16->TabIndex = 12;
			this->button16->UseVisualStyleBackColor = false;
			this->button16->Visible = false;
			// 
			// button17
			// 
			this->button17->BackColor = System::Drawing::Color::Red;
			this->button17->Location = System::Drawing::Point(21, 256);
			this->button17->Name = L"button17";
			this->button17->Size = System::Drawing::Size(23, 23);
			this->button17->TabIndex = 11;
			this->button17->UseVisualStyleBackColor = false;
			this->button17->Visible = false;
			// 
			// pictureBox1
			// 
			this->pictureBox1->Location = System::Drawing::Point(328, 211);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(50, 45);
			this->pictureBox1->TabIndex = 18;
			this->pictureBox1->TabStop = false;
			this->pictureBox1->Click += gcnew System::EventHandler(this, &AddNodeDialog::pictureBox1_Click);
			// 
			// button4
			// 
			this->button4->BackColor = System::Drawing::Color::White;
			this->button4->Location = System::Drawing::Point(224, 256);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(23, 23);
			this->button4->TabIndex = 19;
			this->button4->UseVisualStyleBackColor = false;
			this->button4->Visible = false;
			// 
			// checkBox1
			// 
			this->checkBox1->AutoSize = true;
			this->checkBox1->Location = System::Drawing::Point(21, 211);
			this->checkBox1->Name = L"checkBox1";
			this->checkBox1->Size = System::Drawing::Size(46, 17);
			this->checkBox1->TabIndex = 22;
			this->checkBox1->Text = L"Link";
			this->checkBox1->UseVisualStyleBackColor = true;
			// 
			// checkBox2
			// 
			this->checkBox2->AutoSize = true;
			this->checkBox2->Location = System::Drawing::Point(21, 188);
			this->checkBox2->Name = L"checkBox2";
			this->checkBox2->Size = System::Drawing::Size(79, 17);
			this->checkBox2->TabIndex = 23;
			this->checkBox2->Text = L"Pogrubiony";
			this->checkBox2->UseVisualStyleBackColor = true;
			// 
			// AddNodeDialog
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::SystemColors::ActiveBorder;
			this->ClientSize = System::Drawing::Size(435, 322);
			this->Controls->Add(this->checkBox2);
			this->Controls->Add(this->checkBox1);
			this->Controls->Add(this->button4);
			this->Controls->Add(this->pictureBox1);
			this->Controls->Add(this->button11);
			this->Controls->Add(this->button12);
			this->Controls->Add(this->button13);
			this->Controls->Add(this->button14);
			this->Controls->Add(this->button15);
			this->Controls->Add(this->button16);
			this->Controls->Add(this->button17);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->richTextBox1);
			this->Name = L"AddNodeDialog";
			this->Text = L"AddNodeDialog";
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	
			char* str = (char*)(void*)Marshal::StringToHGlobalAnsi(richTextBox1->Text);
			if(!tree)
			{
				tree=new Root(str,500,350,0);
				tree->link=(int)checkBox1->Checked;
			}
			else
			{
				Node *n=new Node(str,0);
				if((type==0))//||(!ws->getFather()))
				{
					ws->addChild(str,n);	
					ws->first->link=(int)checkBox1->Checked;
				}
				//Bury 10.04.07 od
				//edycja
				else if(type==2)
				{
					
					ws->changeNodeName(str);
					tree->link=(int)checkBox1->Checked;
				

				}
				//Bury 10.04.07 do
				else {
					ws->addBrother(str,n);
					ws->next->link=checkBox1->Checked;
				
				}
			}
			this->Close();
		 }
private: System::Void richTextBox1_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
			 if(e->KeyCode==Windows::Forms::Keys::Enter) {
				char* str = (char*)(void*)Marshal::StringToHGlobalAnsi(richTextBox1->Text);
			 
			if(tree==NULL)
			{
				tree=new Root(str,500,350,0);
				tree->link=(int)checkBox1->Checked;
			}
			else
			{
				Node *n=new Node(str,0);
				if((type==0))
				{
					ws->addChild(str,n);
					tree->link=(int)checkBox1->Checked;
				
				}
				//Bury 10.04.07 od
				//edycja
				else if(type==2)
				{
					
						
					ws->changeNodeName(str);
					tree->link=(int)checkBox1->Checked;
				
				}
				//Bury 10.04.07 do
				else {
					ws->addBrother(str,n);
					ws->next->link=checkBox1->Checked;
				
					}

			}
			 
			 this->Close();
			 }
			 if(e->KeyCode == Windows::Forms::Keys::Escape) this->Close();


		 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			 this->Close();
		 }
private: System::Void pictureBox1_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
			link=1;		
		 
		 }

};
}
